package zhangyu.world.voltaic.generator;


import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.fill.Column;
import com.baomidou.mybatisplus.generator.fill.Property;

import java.util.Arrays;
import java.util.Collections;

/**
 * <p>
 * mysql 代码生成器演示例子
 * </p>
 *
 * @author jobob
 * @since 2018-09-12
 */
public class MysqlGenerator {

    static final String URL = "jdbc:mysql://yft.rdsmbroi0icrzha.rds.bd.baidubce.com/temporary?useUnicode=true&characterEncoding=utf8";
    public static void main(String[] args) {
        String projectPath = System.getProperty("user.dir");//获取项目路径
        FastAutoGenerator.create(URL, "rqt", "qw123123")
                //全局配置
                .globalConfig(builder -> {
                    builder.author("Tian")
                            .outputDir(projectPath + "/src/main/java")//输出路径
//                            .enableSwagger()//开启swagger3
                            .fileOverride()//覆盖文件
                            .disableOpenDir();//不打开文件夹
                })
                //包名配置
                .packageConfig(builder -> {
                    builder.parent("zhangyu.world")
                            .moduleName("safe")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("controller")
                            .entity("entity")
                            .mapper("mapper")
                            //自定义输出路径，mapper.xml生成到resources目录下
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, projectPath + "/src/main/resources/mapper"));
                })
                //策略配置
                .strategyConfig(builder -> {
                    builder.addInclude(Arrays.asList("sc_category","sc_matter"))
//                            .addTablePrefix("t_")//表前缀
//                            .serviceBuilder().formatServiceFileName("%sService")//去掉Service的 "I" 前缀

                            .controllerBuilder().enableRestStyle()//restful开启
                            .enableHyphenStyle()//url改变 例如：index_id_1
                            .entityBuilder().enableLombok()//开启lombok
                            .addTableFills(new Column("create_time", FieldFill.INSERT))
                            .addTableFills(new Property("updateTime", FieldFill.INSERT_UPDATE))
                            .enableChainModel()
                    ;

                })
                //执行
                .execute();
    }
}
